#+TITLE: Eshell prompt
#+AUTHOR: Zelphir Kaltstahl
#+STARTUP: content
#+STARTUP: indent
#+STARTUP: align
#+STARTUP: inlineimages
#+STARTUP: hideblocks
#+STARTUP: entitiesplain
#+STARTUP: nologdone
#+STARTUP: nologreschedule
#+STARTUP: nologredeadline
#+STARTUP: nologrefile
#+TODO: TODO INPROGRESS | DONE CANCELLED
#+DATE: [2023-01-31 Di]
#+LANGUAGE: English
#+PRIORITIES: A E E
#+KEYWORDS: eshell prompt config


* Example configuration

#+begin_src elisp
(defun set-eshell-prompt-function ()
  (setq eshell-prompt-function
        (function
         (lambda ()
           (concat
            (propertize (format-time-string "%H:%M:%S" (current-time))
                        'face
                        `(:foreground "#A0A0A0"))
            "::"
            (propertize (user-login-name)
                        'face
                        `(:foreground "#FF9080"))
            "@"
            (propertize (let ((sys-name (system-name)))
                          (let ((sys-name-len (length sys-name)))
                            (if (> sys-name-len 8)
                                (concat (substring sys-name 0 8) "...")
                              sys-name)))
                        'face
                        `(:foreground "#FF9080"))
            "::"
            (propertize (shorten-filename (eshell/pwd) 36)
                        'face
                        `(:foreground "#FF9080"))
            "::"
            (propertize (concat "("
                                (if-let ((status eshell-last-command-status))
                                    (if (= status 0)
                                        "0"
                                        (format "%s" status)))
                                ")")
                        'face
                        `(:foreground "#FF9080"))
            (if (= (user-uid) 0)
                "# "
                "$ ")))))
  (setq eshell-highlight-prompt t)
  ;; The prompt is:
  ;; + anything except '#', '$', and '\n' an arbitrary number of times followed by
  ;; + '#' or '$' followed by
  ;; + ' '.
  (setq eshell-prompt-regexp "^[^#$\n]*[#$] "))

;; Actually make use of the defined procedure.
(set-eshell-prompt-function)
#+end_src
